package com.fili.core;

import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

/**
 * Created by Claudiu-Florin FILIMON
 * Date: Oct 19, 2006
 * Time: 10:58:46 AM
 * Revision: 0
 */
public class StreamBufferer extends Thread
{
    private BufferedReader buffReader;
    private StringBuffer buffer;
    private boolean finished;


    public StringBuffer getBuffer()
    {
        return buffer;
    }


    public synchronized boolean isFinished()
    {
        return finished;
    }

    public synchronized void setFinished(boolean finished)
    {
        this.finished = finished;
    }

    public StreamBufferer(InputStream inputStream)
    {
        buffReader = new BufferedReader(new InputStreamReader(inputStream));
        buffer = new StringBuffer();
        setFinished(false);
        start();
    }


    public void run()
    {
        String line;

        try
        {
            while ((line = buffReader.readLine()) != null)
                buffer.append(line).append("\n");
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        setFinished(true);
    }
}
